﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using DTO;
using DataService;

public partial class Admin_AccountUser : BasePage
{
    private UserService _userService;
    private IList<User> _users;
    public Admin_AccountUser()
    {
        _userService = new UserService();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(Request.QueryString["ac"]))
        {
            _users = _userService.GetListUserByAccountId(Convert.ToInt32(Request.QueryString["ac"]));
            if (_users.Count > 0)
            {
                lbAccount.Text = "<b>User for Customer " + _users[0].Customer.Code + "</b>";
                gvUsers.DataSource = _users;
                gvUsers.DataBind();
            }
        }
        else
        {
            Response.Write("No User Account ....");
        }
    }
    protected void gvUsers_RowEditing(object sender, GridViewEditEventArgs e)
    {
        gvUsers.EditIndex = e.NewEditIndex;
        gvUsers.DataSource = _users;
        gvUsers.DataBind();
    }
    protected void gvUsers_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        _userService.DeleteUserByUserId(_users[e.RowIndex].Id);
        gvUsers.DataSource = _users;
        gvUsers.DataBind();
    }
    protected void gvUsers_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        //User user = _users[e.RowIndex];
        //TextBox txtPassword=(TextBox)gvUsers.Rows[e.RowIndex].Cells[2].Controls[0];
        //_userService.InsertUpdateUserInfo(user.Customer.Id,user.Id,user.Username,
    }
    protected void gvUsers_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        gvUsers.EditIndex = -1;
        gvUsers.DataSource = _users;
        gvUsers.DataBind();
    }
}